m-new"> 3536
+  "610800": {
3537
+    "610802": "榆阳区",
3538
+    "610803": "横山区",
3539
+    "610821": "神木县",
3540
+    "610822": "府谷县",
3541
+    "610824": "靖边县",
3542
+    "610825": "定边县",
3543
+    "610826": "绥德县",
3544
+    "610827": "米脂县",
3545
+    "610828": "佳县",
3546
+    "610829": "吴堡县",
3547
+    "610830": "清涧县",
3548
+    "610831": "子洲县"
3549
+  },
3550
+  "610900": {
3551
+    "610902": "汉滨区",
3552
+    "610921": "汉阴县",
3553
+    "610922": "石泉县",
3554
+    "610923": "宁陕县",
3555
+    "610924": "紫阳县",
3556
+    "610925": "岚皋县",
3557
+    "610926": "平利县",
3558
+    "610927": "镇坪县",
3559
+    "610928": "旬阳县",
3560
+    "610929": "白河县"
3561
+  },
3562
+  "611000": {
3563
+    "611002": "商州区",
3564
+    "611021": "洛南县",
3565
+    "611022": "丹凤县",
3566
+    "611023": "商南县",
3567
+    "611024": "山阳县",
3568
+    "611025": "镇安县",
3569
+    "611026": "柞水县"
3570
+  },
3571
+  "620000": {
3572
+    "620100": "兰州市",
3573
+    "620200": "嘉峪关市",
3574
+    "620300": "金昌市",
3575
+    "620400": "白银市",
3576
+    "620500": "天水市",
3577
+    "620600": "武威市",
3578
+    "620700": "张掖市",
3579
+    "620800": "平凉市",
3580
+    "620900": "酒泉市",
3581
+    "621000": "庆阳市",
3582
+    "621100": "定西市",
3583
+    "621200": "陇南市",
3584
+    "622900": "临夏回族自治州",
3585
+    "623000": "甘南藏族自治州"
3586
+  },
3587
+  "620100": {
3588
+    "620102": "城关区",
3589
+    "620103": "七里河区",
3590
+    "620104": "西固区",
3591
+    "620105": "安宁区",
3592
+    "620111": "红古区",
3593
+    "620121": "永登县",
3594
+    "620122": "皋兰县",
3595
+    "620123": "榆中县"
3596
+  },
3597
+  "620300": {
3598
+    "620302": "金川区",
3599
+    "620321": "永昌县"
3600
+  },
3601
+  "620400": {
3602
+    "620402": "白银区",
3603
+    "620403": "平川区",
3604
+    "620421": "靖远县",
3605
+    "620422": "会宁县",
3606
+    "620423": "景泰县"
3607
+  },
3608
+  "620500": {
3609
+    "620502": "秦州区",
3610
+    "620503": "麦积区",
3611
+    "620521": "清水县",
3612
+    "620522": "秦安县",
3613
+    "620523": "甘谷县",
3614
+    "620524": "武山县",
3615
+    "620525": "张家川回族自治县"
3616
+  },
3617
+  "620600": {
3618
+    "620602": "凉州区",
3619
+    "620621": "民勤县",
3620
+    "620622": "古浪县",
3621
+    "620623": "天祝藏族自治县"
3622
+  },
3623
+  "620700": {
3624
+    "620702": "甘州区",
3625
+    "620721": "肃南裕固族自治县",
3626
+    "620722": "民乐县",
3627
+    "620723": "临泽县",
3628
+    "620724": "高台县",
3629
+    "620725": "山丹县"
3630
+  },
3631
+  "620800": {
3632
+    "620802": "崆峒区",
3633
+    "620821": "泾川县",
3634
+    "620822": "灵台县",
3635
+    "620823": "崇信县",
3636
+    "620824": "华亭县",
3637
+    "620825": "庄浪县",
3638
+    "620826": "静宁县"
3639
+  },
3640
+  "620900": {
3641
+    "620902": "肃州区",
3642
+    "620921": "金塔县",
3643
+    "620922": "瓜州县",
3644
+    "620923": "肃北蒙古族自治县",
3645
+    "620924": "阿克塞哈萨克族自治县",
3646
+    "620981": "玉门市",
3647
+    "620982": "敦煌市"
3648
+  },
3649
+  "621000": {
3650
+    "621002": "西峰区",
3651
+    "621021": "庆城县",
3652
+    "621022": "环县",
3653
+    "621023": "华池县",
3654
+    "621024": "合水县",
3655
+    "621025": "正宁县",
3656
+    "621026": "宁县",
3657
+    "621027": "镇原县"
3658
+  },
3659
+  "621100": {
3660
+    "621102": "安定区",
3661
+    "621121": "通渭县",
3662
+    "621122": "陇西县",
3663
+    "621123": "渭源县",
3664
+    "621124": "临洮县",
3665
+    "621125": "漳县",
3666
+    "621126": "岷县"
3667
+  },
3668
+  "621200": {
3669
+    "621202": "武都区",
3670
+    "621221": "成县",
3671
+    "621222": "文县",
3672
+    "621223": "宕昌县",
3673
+    "621224": "康县",
3674
+    "621225": "西和县",
3675
+    "621226": "礼县",
3676
+    "621227": "徽县",
3677
+    "621228": "两当县"
3678
+  },
3679
+  "622900": {
3680
+    "622901": "临夏市",
3681
+    "622921": "临夏县",
3682
+    "622922": "康乐县",
3683
+    "622923": "永靖县",
3684
+    "622924": "广河县",
3685
+    "622925": "和政县",
3686
+    "622926": "东乡族自治县",
3687
+    "622927": "积石山保安族东乡族撒拉族自治县"
3688
+  },
3689
+  "623000": {
3690
+    "623001": "合作市",
3691
+    "623021": "临潭县",
3692
+    "623022": "卓尼县",
3693
+    "623023": "舟曲县",
3694
+    "623024": "迭部县",
3695
+    "623025": "玛曲县",
3696
+    "623026": "碌曲县",
3697
+    "623027": "夏河县"
3698
+  },
3699
+  "630000": {
3700
+    "630100": "西宁市",
3701
+    "630200": "海东市",
3702
+    "632200": "海北藏族自治州",
3703
+    "632300": "黄南藏族自治州",
3704
+    "632500": "海南藏族自治州",
3705
+    "632600": "果洛藏族自治州",
3706
+    "632700": "玉树藏族自治州",
3707
+    "632800": "海西蒙古族藏族自治州"
3708
+  },
3709
+  "630100": {
3710
+    "630102": "城东区",
3711
+    "630103": "城中区",
3712
+    "630104": "城西区",
3713
+    "630105": "城北区",
3714
+    "630121": "大通回族土族自治县",
3715
+    "630122": "湟中县",
3716
+    "630123": "湟源县"
3717
+  },
3718
+  "630200": {
3719
+    "630202": "乐都区",
3720
+    "630203": "平安区",
3721
+    "630222": "民和回族土族自治县",
3722
+    "630223": "互助土族自治县",
3723
+    "630224": "化隆回族自治县",
3724
+    "630225": "循化撒拉族自治县"
3725
+  },
3726
+  "632200": {
3727
+    "632221": "门源回族自治县",
3728
+    "632222": "祁连县",
3729
+    "632223": "海晏县",
3730
+    "632224": "刚察县"
3731
+  },
3732
+  "632300": {
3733
+    "632321": "同仁县",
3734
+    "632322": "尖扎县",
3735
+    "632323": "泽库县",
3736
+    "632324": "河南蒙古族自治县"
3737
+  },
3738
+  "632500": {
3739
+    "632521": "共和县",
3740
+    "632522": "同德县",
3741
+    "632523": "贵德县",
3742
+    "632524": "兴海县",
3743
+    "632525": "贵南县"
3744
+  },
3745
+  "632600": {
3746
+    "632621": "玛沁县",
3747
+    "632622": "班玛县",
3748
+    "632623": "甘德县",
3749
+    "632624": "达日县",
3750
+    "632625": "久治县",
3751
+    "632626": "玛多县"
3752
+  },
3753
+  "632700": {
3754
+    "632701": "玉树市",
3755
+    "632722": "杂多县",
3756
+    "632723": "称多县",
3757
+    "632724": "治多县",
3758
+    "632725": "囊谦县",
3759
+    "632726": "曲麻莱县"
3760
+  },
3761
+  "632800": {
3762
+    "632801": "格尔木市",
3763
+    "632802": "德令哈市",
3764
+    "632821": "乌兰县",
3765
+    "632822": "都兰县",
3766
+    "632823": "天峻县"
3767
+  },
3768
+  "640000": {
3769
+    "640100": "银川市",
3770
+    "640200": "石嘴山市",
3771
+    "640300": "吴忠市",
3772
+    "640400": "固原市",
3773
+    "640500": "中卫市"
3774
+  },
3775
+  "640100": {
3776
+    "640104": "兴庆区",
3777
+    "640105": "西夏区",
3778
+    "640106": "金凤区",
3779
+    "640121": "永宁县",
3780
+    "640122": "贺兰县",
3781
+    "640181": "灵武市"
3782
+  },
3783
+  "640200": {
3784
+    "640202": "大武口区",
3785
+    "640205": "惠农区",
3786
+    "640221": "平罗县"
3787
+  },
3788
+  "640300": {
3789
+    "640302": "利通区",
3790
+    "640303": "红寺堡区",
3791
+    "640323": "盐池县",
3792
+    "640324": "同心县",
3793
+    "640381": "青铜峡市"
3794
+  },
3795
+  "640400": {
3796
+    "640402": "原州区",
3797
+    "640422": "西吉县",
3798
+    "640423": "隆德县",
3799
+    "640424": "泾源县",
3800
+    "640425": "彭阳县"
3801
+  },
3802
+  "640500": {
3803
+    "640502": "沙坡头区",
3804
+    "640521": "中宁县",
3805
+    "640522": "海原县"
3806
+  },
3807
+  "650000": {
3808
+    "650100": "乌鲁木齐市",
3809
+    "650200": "克拉玛依市",
3810
+    "650400": "吐鲁番市",
3811
+    "650500": "哈密市",
3812
+    "652300": "昌吉回族自治州",
3813
+    "652700": "博尔塔拉蒙古自治州",
3814
+    "652800": "巴音郭楞蒙古自治州",
3815
+    "652900": "阿克苏地区",
3816
+    "653000": "克孜勒苏柯尔克孜自治州",
3817
+    "653100": "喀什地区",
3818
+    "653200": "和田地区",
3819
+    "654000": "伊犁哈萨克自治州",
3820
+    "654200": "塔城地区",
3821
+    "654300": "阿勒泰地区",
3822
+    "659001": "石河子市",
3823
+    "659002": "阿拉尔市",
3824
+    "659003": "图木舒克市",
3825
+    "659004": "五家渠市",
3826
+    "659006": "铁门关市"
3827
+  },
3828
+  "650100": {
3829
+    "650102": "天山区",
3830
+    "650103": "沙依巴克区",
3831
+    "650104": "新市区",
3832
+    "650105": "水磨沟区",
3833
+    "650106": "头屯河区",
3834
+    "650107": "达坂城区",
3835
+    "650109": "米东区",
3836
+    "650121": "乌鲁木齐县"
3837
+  },
3838
+  "650200": {
3839
+    "650202": "独山子区",
3840
+    "650203": "克拉玛依区",
3841
+    "650204": "白碱滩区",
3842
+    "650205": "乌尔禾区"
3843
+  },
3844
+  "650400": {
3845
+    "650402": "高昌区",
3846
+    "650421": "鄯善县",
3847
+    "650422": "托克逊县"
3848
+  },
3849
+  "650500": {
3850
+    "650502": "伊州区",
3851
+    "650521": "巴里坤哈萨克自治县",
3852
+    "650522": "伊吾县"
3853
+  },
3854
+  "652300": {
3855
+    "652301": "昌吉市",
3856
+    "652302": "阜康市",
3857
+    "652323": "呼图壁县",
3858
+    "652324": "玛纳斯县",
3859
+    "652325": "奇台县",
3860
+    "652327": "吉木萨尔县",
3861
+    "652328": "木垒哈萨克自治县"
3862
+  },
3863
+  "652700": {
3864
+    "652701": "博乐市",
3865
+    "652702": "阿拉山口市",
3866
+    "652722": "精河县",
3867
+    "652723": "温泉县"
3868
+  },
3869
+  "652800": {
3870
+    "652801": "库尔勒市",
3871
+    "652822": "轮台县",
3872
+    "652823": "尉犁县",
3873
+    "652824": "若羌县",
3874
+    "652825": "且末县",
3875
+    "652826": "焉耆回族自治县",
3876
+    "652827": "和静县",
3877
+    "652828": "和硕县",
3878
+    "652829": "博湖县"
3879
+  },
3880
+  "652900": {
3881
+    "652901": "阿克苏市",
3882
+    "652922": "温宿县",
3883
+    "652923": "库车县",
3884
+    "652924": "沙雅县",
3885
+    "652925": "新和县",
3886
+    "652926": "拜城县",
3887
+    "652927": "乌什县",
3888
+    "652928": "阿瓦提县",
3889
+    "652929": "柯坪县"
3890
+  },
3891
+  "653000": {
3892
+    "653001": "阿图什市",
3893
+    "653022": "阿克陶县",
3894
+    "653023": "阿合奇县",
3895
+    "653024": "乌恰县"
3896
+  },
3897
+  "653100": {
3898
+    "653101": "喀什市",
3899
+    "653121": "疏附县",
3900
+    "653122": "疏勒县",
3901
+    "653123": "英吉沙县",
3902
+    "653124": "泽普县",
3903
+    "653125": "莎车县",
3904
+    "653126": "叶城县",
3905
+    "653127": "麦盖提县",
3906
+    "653128": "岳普湖县",
3907
+    "653129": "伽师县",
3908
+    "653130": "巴楚县",
3909
+    "653131": "塔什库尔干塔吉克自治县"
3910
+  },
3911
+  "653200": {
3912
+    "653201": "和田市",
3913
+    "653221": "和田县",
3914
+    "653222": "墨玉县",
3915
+    "653223": "皮山县",
3916
+    "653224": "洛浦县",
3917
+    "653225": "策勒县",
3918
+    "653226": "于田县",
3919
+    "653227": "民丰县"
3920
+  },
3921
+  "654000": {
3922
+    "654002": "伊宁市",
3923
+    "654003": "奎屯市",
3924
+    "654004": "霍尔果斯市",
3925
+    "654021": "伊宁县",
3926
+    "654022": "察布查尔锡伯自治县",
3927
+    "654023": "霍城县",
3928
+    "654024": "巩留县",
3929
+    "654025": "新源县",
3930
+    "654026": "昭苏县",
3931
+    "654027": "特克斯县",
3932
+    "654028": "尼勒克县"
3933
+  },
3934
+  "654200": {
3935
+    "654201": "塔城市",
3936
+    "654202": "乌苏市",
3937
+    "654221": "额敏县",
3938
+    "654223": "沙湾县",
3939
+    "654224": "托里县",
3940
+    "654225": "裕民县",
3941
+    "654226": "和布克赛尔蒙古自治县"
3942
+  },
3943
+  "654300": {
3944
+    "654301": "阿勒泰市",
3945
+    "654321": "布尔津县",
3946
+    "654322": "富蕴县",
3947
+    "654323": "福海县",
3948
+    "654324": "哈巴河县",
3949
+    "654325": "青河县",
3950
+    "654326": "吉木乃县"
3951
+  },
3952
+  "810000": {
3953
+    "810001": "中西區",
3954
+    "810002": "灣仔區",
3955
+    "810003": "東區",
3956
+    "810004": "南區",
3957
+    "810005": "油尖旺區",
3958
+    "810006": "深水埗區",
3959
+    "810007": "九龍城區",
3960
+    "810008": "黃大仙區",
3961
+    "810009": "觀塘區",
3962
+    "810010": "荃灣區",
3963
+    "810011": "屯門區",
3964
+    "810012": "元朗區",
3965
+    "810013": "北區",
3966
+    "810014": "大埔區",
3967
+    "810015": "西貢區",
3968
+    "810016": "沙田區",
3969
+    "810017": "葵青區",
3970
+    "810018": "離島區"
3971
+  },
3972
+  "820000": {
3973
+    "820001": "花地瑪堂區",
3974
+    "820002": "花王堂區",
3975
+    "820003": "望德堂區",
3976
+    "820004": "大堂區",
3977
+    "820005": "風順堂區",
3978
+    "820006": "嘉模堂區",
3979
+    "820007": "路氹填海區",
3980
+    "820008": "聖方濟各堂區"
3981
+  }
3982
+}

+ 7 - 0
data/tests.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.test import TestCase
5
+
6
+
7
+# Create your tests here.

+ 7 - 0
data/views.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.shortcuts import render
5
+
6
+
7
+# Create your views here.

+ 0 - 0
encrypt/__init__.py


+ 7 - 0
encrypt/admin.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.contrib import admin
5
+
6
+
7
+# Register your models here.

+ 8 - 0
encrypt/apps.py

@@ -0,0 +1,8 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.apps import AppConfig
5
+
6
+
7
+class EncryptConfig(AppConfig):
8
+    name = 'encrypt'

+ 33 - 0
encrypt/migrations/0001_initial.py

@@ -0,0 +1,33 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.3 on 2017-12-30 13:37
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+import shortuuidfield.fields
7
+
8
+
9
+class Migration(migrations.Migration):
10
+
11
+    initial = True
12
+
13
+    dependencies = [
14
+    ]
15
+
16
+    operations = [
17
+        migrations.CreateModel(
18
+            name='EncryptTextInfo',
19
+            fields=[
20
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
22
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
23
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
24
+                ('ciphertext', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u5bc6\u6587', max_length=22, null=True)),
25
+                ('plaintext', models.TextField(blank=True, help_text='\u660e\u6587', null=True, verbose_name='plaintext')),
26
+                ('plaintext_md5', models.CharField(blank=True, help_text='\u660e\u6587MD5', max_length=32, null=True, verbose_name='plaintext')),
27
+            ],
28
+            options={
29
+                'verbose_name': 'encrypttextinfo',
30
+                'verbose_name_plural': 'encrypttextinfo',
31
+            },
32
+        ),
33
+    ]

+ 0 - 0
encrypt/migrations/__init__.py


+ 19 - 0
encrypt/models.py

@@ -0,0 +1,19 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django.db import models
4
+from django.utils.translation import ugettext_lazy as _
5
+from models_ext.basemodels import BaseModelMixin
6
+from shortuuidfield import ShortUUIDField
7
+
8
+
9
+class EncryptTextInfo(BaseModelMixin):
10
+    ciphertext = ShortUUIDField(_(u'ciphertext'), max_length=32, blank=True, null=True, help_text=u'密文', db_index=True)
11
+    plaintext = models.TextField(_(u'plaintext'), blank=True, null=True, help_text=_(u'明文'))
12
+    plaintext_md5 = models.CharField(_(u'plaintext'), max_length=32, blank=True, null=True, help_text=_(u'明文MD5'))
13
+
14
+    class Meta:
15
+        verbose_name = _(u'encrypttextinfo')
16
+        verbose_name_plural = _(u'encrypttextinfo')
17
+
18
+    def __unicode__(self):
19
+        return u'{0.pk}'.format(self)

+ 7 - 0
encrypt/tests.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.test import TestCase
5
+
6
+
7
+# Create your tests here.

+ 7 - 0
encrypt/views.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.shortcuts import render
5
+
6
+
7
+# Create your views here.

+ 3 - 0
isort.sh

@@ -0,0 +1,3 @@
1
+#!/bin/bash
2
+
3
+isort -rc -sp . .

+ 0 - 0
kodo/__init__.py


+ 54 - 0
kodo/decorators.py

@@ -0,0 +1,54 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from functools import wraps
4
+
5
+from django.conf import settings
6
+from django.shortcuts import redirect
7
+from furl import furl
8
+from pywe_oauth import get_oauth_redirect_url
9
+from pywe_sign import check_signature
10
+
11
+from utils.error.errno_utils import SignatureStatusCode
12
+from utils.error.response_utils import response
13
+from utils.redis.connect import r
14
+
15
+
16
+def check_token(func=None, entry=None):
17
+    def decorator(func):
18
+        @wraps(func)
19
+        def returned_wrapper(request, *args, **kwargs):
20
+            if not settings.DEBUG and request.wechat:
21
+                vtoken = request.GET.get('vtoken', '') or request.POST.get('vtoken', '')
22
+                token_check_key = request.GET.get(settings.TOKEN_CHECK_KEY, '') or request.POST.get(settings.TOKEN_CHECK_KEY, '')
23
+                if not r.token_exists(token_check_key, vtoken):
24
+                    # 3rd OAuth
25
+                    # return redirect(settings.WECHAT_OAUTH2_REDIRECT_URL)
26
+                    # Current OAuth
27
+                    redirect_url = furl(entry or settings.WECHAT_OAUTH2_REDIRECT_ENTRY).add({}).url
28
+                    return redirect(get_oauth_redirect_url(settings.WECHAT_OAUTH2_REDIRECT_URI, 'snsapi_userinfo', redirect_url))
29
+            return func(request, *args, **kwargs)
30
+        return returned_wrapper
31
+
32
+    if not func:
33
+        def foo(func):
34
+            return decorator(func)
35
+        return foo
36
+
37
+    return decorator(func)
38
+
39
+
40
+def check_sign(func=None, method='POST'):
41
+    def decorator(func):
42
+        @wraps(func)
43
+        def returned_wrapper(request, *args, **kwargs):
44
+            if not settings.DEBUG and not check_signature(getattr(request, method).dict(), settings.PARAMS_SIGN_KEY):
45
+                return response(SignatureStatusCode.SIGNATURE_ERROR)
46
+            return func(request, *args, **kwargs)
47
+        return returned_wrapper
48
+
49
+    if not func:
50
+        def foo(func):
51
+            return decorator(func)
52
+        return foo
53
+
54
+    return decorator(func)

+ 27 - 0
kodo/deploy.bak/kodo.ini

@@ -0,0 +1,27 @@
1
+# kodo_uwsgi.ini file
2
+[uwsgi]
3
+
4
+# Django-related settings
5
+# the base directory (full path)
6
+chdir           = /home/paiai/work/kodo
7
+# Django's wsgi file
8
+module          = kodo.wsgi
9
+# the virtualenv (full path)
10
+# home            = /path/to/virtualenv
11
+
12
+# process-related settings
13
+# master
14
+master          = true
15
+# maximum number of worker processes
16
+processes       = 10
17
+# the socket (use the full path to be safe
18
+socket          = /home/paiai/work/kodo/kodo/deploy/kodo.sock
19
+# ... with appropriate permissions - may be needed
20
+chmod-socket    = 777
21
+# clear environment on exit
22
+vacuum          = true
23
+
24
+# 11: Resource temporarily unavailable
25
+reload-mercy    = 64
26
+max-requests    = 8192
27
+listen          = 4096

+ 40 - 0
kodo/deploy.bak/kodo_nginx.conf

@@ -0,0 +1,40 @@
1
+# kodo_nginx.conf
2
+
3
+# the upstream component nginx needs to connect to
4
+upstream kodo {
5
+    # server unix:///home/paiai/work/kodo/kodo/deploy/kodo.sock; # for a file socket
6
+    server 127.0.0.1:8888; # for a web port socket (we'll use this first)
7
+}
8
+
9
+# configuration of the server
10
+server {
11
+    # the port your site will be served on
12
+    listen      80;
13
+    # the domain name it will serve for
14
+    server_name .a.com; # substitute your machine's IP address or FQDN
15
+    charset     utf-8;
16
+
17
+    # max upload size
18
+    client_max_body_size 75M;   # adjust to taste
19
+
20
+    # JS接口安全域名 & 业务域名 验证
21
+    location /xxx.txt {
22
+        alias /home/paiai/work/kodo/docs/we/xxx.txt;
23
+    }
24
+
25
+    # Django media
26
+    location /media  {
27
+        alias /home/paiai/work/kodo/media;  # your Django project's media files - amend as required
28
+    }
29
+
30
+    location /static {
31
+        alias /home/paiai/work/kodo/collect_static; # your Django project's static files - amend as required
32
+    }
33
+
34
+    # Finally, send all non-media requests to the Django server.
35
+    location / {
36
+        # uwsgi_pass  kodo;
37
+        proxy_pass  http://kodo;
38
+        include     /home/paiai/work/kodo/kodo/deploy/uwsgi_params; # the uwsgi_params file you installed
39
+    }
40
+}

+ 10 - 0
kodo/deploy.bak/kodo_supervisor.ini

@@ -0,0 +1,10 @@
1
+[program:kodo]
2
+command=/home/paiai/env/bin/uwsgi --ini /home/diors/work/kodo/kodo/deploy/kodo.ini
3
+autostart=true
4
+autorestart=true
5
+startretries=3
6
+exitcodes=0,1,2
7
+stopsignal=QUIT
8
+stdout_logfile=/var/log/supervisor_kodo_access.log
9
+stderr_logfile=/var/log/supervisor_kodo_error.log
10
+user=diors

+ 15 - 0
kodo/deploy.bak/uwsgi_params

@@ -0,0 +1,15 @@
1
+uwsgi_param	QUERY_STRING		$query_string;
2
+uwsgi_param	REQUEST_METHOD		$request_method;
3
+uwsgi_param	CONTENT_TYPE		$content_type;
4
+uwsgi_param	CONTENT_LENGTH		$content_length;
5
+
6
+uwsgi_param	REQUEST_URI		$request_uri;
7
+uwsgi_param	PATH_INFO		$document_uri;
8
+uwsgi_param	DOCUMENT_ROOT		$document_root;
9
+uwsgi_param	SERVER_PROTOCOL		$server_protocol;
10
+uwsgi_param	UWSGI_SCHEME		$scheme;
11
+
12
+uwsgi_param	REMOTE_ADDR		$remote_addr;
13
+uwsgi_param	REMOTE_PORT		$remote_port;
14
+uwsgi_param	SERVER_PORT		$server_port;
15
+uwsgi_param	SERVER_NAME		$server_name;

+ 16 - 0
kodo/func_settings.py

@@ -0,0 +1,16 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import redis_extensions as redis
4
+
5
+
6
+def redis_conf(conf):
7
+    return {
8
+        'host': conf.get('HOST', 'localhost'),
9
+        'port': conf.get('PORT', 6379),
10
+        'password': '{0}:{1}'.format(conf.get('USER', ''), conf.get('PASSWORD', '')) if conf.get('USER') else '',
11
+        'db': conf.get('db', 0),
12
+    }
13
+
14
+
15
+def redis_connect(conf):
16
+    return redis.StrictRedisExtensions(connection_pool=redis.ConnectionPool(**redis_conf(conf)))

+ 17 - 0
kodo/local_settings_bak.py

@@ -0,0 +1,17 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+# DEBUG = False
4
+
5
+ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'kodo']
6
+
7
+# DOMAIN
8
+DOMAIN = 'http://a.com'
9
+
10
+# 邮件设置
11
+# 只有当 DEBUG = False 的时候,才会邮件发送报错信息
12
+SERVER_EMAIL = 'error.notify@exmail.com'
13
+EMAIL_HOST_USER = 'error.notify@exmail.com'
14
+EMAIL_HOST_PASSWORD = '<^_^>pwd<^_^>'
15
+DEFAULT_FROM_EMAIL = 'error.notify <error.notify@exmail.com>'
16
+ADMINS = [('Zhang San', 'san.zhang@exmail.com'), ('Li Si', 'si.li@exmail.com')]
17
+EMAIL_SUBJECT_PREFIX = u'[Kodo] '

+ 27 - 0
kodo/local_settings_dev_bak.py

@@ -0,0 +1,27 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import os
4
+
5
+
6
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7
+PROJ_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
8
+
9
+TEMPLATES = [
10
+    {
11
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
12
+        'DIRS': [os.path.join(BASE_DIR, 'templates')],
13
+        # 'APP_DIRS': True,
14
+        'OPTIONS': {
15
+            'context_processors': [
16
+                'django.template.context_processors.debug',
17
+                'django.template.context_processors.request',
18
+                'django.contrib.auth.context_processors.auth',
19
+                'django.contrib.messages.context_processors.messages',
20
+            ],
21
+            'loaders': [
22
+                'django.template.loaders.filesystem.Loader',
23
+                'django.template.loaders.app_directories.Loader',
24
+            ],
25
+        },
26
+    },
27
+]

+ 44 - 0
kodo/oauth_settings.py

@@ -0,0 +1,44 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+
4
+def DJANGO_WE_CFG_FUNC(request, state=None):
5
+    """ WeChat CFG Callback Func """
6
+
7
+
8
+def DJANGO_WE_QUOTE_STATE_FUNC(request, state):
9
+    """ WeChat Quote Callback Func """
10
+    from utils.redis.connect import r
11
+    return r.quote(state)
12
+
13
+
14
+def DJANGO_WE_UNQUOTE_STATE_FUNC(request, state):
15
+    """ WeChat UnQuote Callback Func """
16
+    from utils.redis.connect import r
17
+    return r.unquote(state) or state
18
+
19
+
20
+def DJANGO_WE_BASE_FUNC(code, state, access_info=None):
21
+    """ WeChat Base Redirect Callback Func """
22
+
23
+
24
+def DJANGO_WE_USERINFO_FUNC(code, state, access_info=None, userinfo=None):
25
+    """ WeChat Userinfo Redirect Callback Func """
26
+    from django.conf import settings
27
+    from utils.redis.connect import r
28
+    from utils.user.userinfo_save import userinfo_save
29
+
30
+    # Save profile or something else
31
+    user = userinfo_save(userinfo)
32
+
33
+    token_check_key = getattr(user, settings.TOKEN_CHECK_KEY)
34
+
35
+    return {
36
+        settings.TOKEN_CHECK_KEY: token_check_key,
37
+        'vtoken': r.token(token_check_key, ex=False, buf=False),
38
+    }
39
+
40
+
41
+def DJANGO_WE_SHARE_FUNC(request, state=None):
42
+    """ WeChat Share Callback Func """
43
+    # from django.conf import settings
44
+    # return settings.WECHAT_OAUTH2_REDIRECT_URL

+ 321 - 0
kodo/settings.py

@@ -0,0 +1,321 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+"""
4
+Django settings for kodo project.
5
+
6
+Generated by 'django-admin startproject' using Django 1.11.3.
7
+
8
+For more information on this file, see
9
+https://docs.djangoproject.com/en/1.11/topics/settings/
10
+
11
+For the full list of settings and their values, see
12
+https://docs.djangoproject.com/en/1.11/ref/settings/
13
+"""
14
+
15
+import os
16
+
17
+
18
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
19
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
20
+PROJ_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
21
+
22
+
23
+# Quick-start development settings - unsuitable for production
24
+# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
25
+
26
+# SECURITY WARNING: keep the secret key used in production secret!
27
+SECRET_KEY = '0=hpv21&am(7(k5ab!^zjvvl=ntj)^i@7)87t47uzumt_5rq$+'
28
+
29
+# SECURITY WARNING: don't run with debug turned on in production!
30
+DEBUG = True
31
+
32
+ALLOWED_HOSTS = []
33
+
34
+
35
+# Application definition
36
+
37
+INSTALLED_APPS = [
38
+    'django.contrib.admin',
39
+    'django.contrib.auth',
40
+    'django.contrib.contenttypes',
41
+    'django.contrib.sessions',
42
+    'django.contrib.messages',
43
+    'django.contrib.staticfiles',
44
+    # 'django_short_url',
45
+    'django_uniapi',
46
+    'django_we',
47
+    'api',
48
+    'encrypt',
49
+    'mch',
50
+]
51
+
52
+MIDDLEWARE = [
53
+    'django.middleware.security.SecurityMiddleware',
54
+    'django.contrib.sessions.middleware.SessionMiddleware',
55
+    'django.middleware.common.CommonMiddleware',
56
+    # 'django.middleware.csrf.CsrfViewMiddleware',
57
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
58
+    'django.contrib.messages.middleware.MessageMiddleware',
59
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
60
+    'detect.middleware.UserAgentDetectionMiddleware',
61
+]
62
+
63
+ROOT_URLCONF = 'kodo.urls'
64
+
65
+TEMPLATES = [
66
+    {
67
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
68
+        'DIRS': [os.path.join(BASE_DIR, 'templates')],
69
+        # 'APP_DIRS': True,
70
+        'OPTIONS': {
71
+            'context_processors': [
72
+                'django.template.context_processors.debug',
73
+                'django.template.context_processors.request',
74
+                'django.contrib.auth.context_processors.auth',
75
+                'django.contrib.messages.context_processors.messages',
76
+            ],
77
+            'loaders': [
78
+                ('django.template.loaders.cached.Loader', [
79
+                    'django.template.loaders.filesystem.Loader',
80
+                    'django.template.loaders.app_directories.Loader',
81
+                ]),
82
+            ],
83
+        },
84
+    },
85
+]
86
+
87
+WSGI_APPLICATION = 'kodo.wsgi.application'
88
+
89
+
90
+# Database
91
+# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
92
+
93
+DATABASES = {
94
+    'default': {
95
+        'ENGINE': 'django.db.backends.mysql',
96
+        'NAME': 'kodo',
97
+        'USER': 'root',
98
+        'PASSWORD': '',
99
+        'HOST': '127.0.0.1',
100
+        'PORT': 3306,
101
+        'CONN_MAX_AGE': 600,
102
+        'OPTIONS': {
103
+            # Utf8mb4 for Emoji
104
+            #
105
+            # Nickname
106
+            #
107
+            # account.WechatInfo ==> nickname
108
+            #   ALTER TABLE account_wechatinfo MODIFY COLUMN nickname VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
109
+            'charset': 'utf8mb4',
110
+        },
111
+    }
112
+}
113
+
114
+
115
+# Password validation
116
+# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
117
+
118
+AUTH_PASSWORD_VALIDATORS = [
119
+    {
120
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
121
+    },
122
+    {
123
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
124
+    },
125
+    {
126
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
127
+    },
128
+    {
129
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
130
+    },
131
+]
132
+
133
+
134
+# Internationalization
135
+# https://docs.djangoproject.com/en/1.11/topics/i18n/
136
+
137
+LANGUAGE_CODE = 'zh-Hans'
138
+
139
+TIME_ZONE = 'Asia/Shanghai'
140
+
141
+USE_I18N = True
142
+
143
+USE_L10N = True
144
+
145
+USE_TZ = True
146
+
147
+
148
+# Static files (CSS, JavaScript, Images)
149
+# https://docs.djangoproject.com/en/1.11/howto/static-files/
150
+
151
+STATICFILES_DIRS = (
152
+    os.path.join(PROJ_DIR, 'static').replace('\\', '/'),
153
+)
154
+
155
+STATIC_ROOT = os.path.join(BASE_DIR, 'collect_static').replace('\\', '/')
156
+
157
+STATIC_URL = '/static/'
158
+
159
+STATICFILES_FINDERS = (
160
+    'django.contrib.staticfiles.finders.FileSystemFinder',
161
+    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
162
+    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
163
+)
164
+
165
+MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
166
+
167
+MEDIA_URL = '/media/'
168
+
169
+# File 设置
170
+FILE_UPLOAD_MAX_MEMORY_SIZE = 5242880  # InMemoryUploadedFile 文件最大值,设置为 5 MB
171
+FILE_UPLOAD_PERMISSIONS = 0o644  # TemporaryUploadedFile 文件权限设置
172
+
173
+# DOMAIN
174
+DOMAIN = 'http://a.com'
175
+
176
+# Redis 设置
177
+REDIS = {
178
+    'default': {
179
+        'HOST': '127.0.0.1',
180
+        'PORT': 6379,
181
+        'USER': '',
182
+        'PASSWORD': '',
183
+        'db': 0,
184
+    }
185
+}
186
+
187
+# 微信设置
188
+WECHAT = {
189
+    'JSAPI': {
190
+        'token': '5201314',
191
+        'appID': '',
192
+        'appsecret': '',
193
+        'mchID': '',
194
+        'apiKey': '',
195
+        'mch_cert': '',
196
+        'mch_key': '',
197
+        'redpack': {
198
+
199
+        }
200
+    },
201
+}
202
+
203
+# 微信唯一标识
204
+# Choices: 'unionid' or 'openid'
205
+#
206
+# models.py
207
+#   'unique_identifier': self.unionid if settings.WECHAT_UNIQUE_IDENTIFICATION == 'unionid' else self.openid,
208
+# views.py
209
+#   unique_identifier = request.POST.get(settings.WECHAT_UNIQUE_IDENTIFICATION, '')
210
+#   profile = Profile.objects.get(**{settings.WECHAT_UNIQUE_IDENTIFICATION: unique_identifier})
211
+WECHAT_UNIQUE_IDENTIFICATION = 'unionid'
212
+
213
+# Token 错误重授权设置
214
+TOKEN_CHECK_KEY = ''
215
+# TOKEN_CHECK_KEY = 'user_id'
216
+WECHAT_OAUTH2_REDIRECT_ENTRY = ''
217
+WECHAT_OAUTH2_REDIRECT_URL = ''
218
+
219
+# 邮件设置
220
+# https://docs.djangoproject.com/en/1.11/howto/error-reporting/#email-reports
221
+# When DEBUG is False, Django will email the users listed in the ADMINS setting
222
+# whenever your code raises an unhandled exception and results in an internal server error (HTTP status code 500).
223
+# 只有当 DEBUG = False 的时候,才会邮件发送报错信息
224
+# Email address that error messages come from.
225
+SERVER_EMAIL = 'error.notify@exmail.com'
226
+# The email backend to use. For possible shortcuts see django.core.mail.
227
+# The default is to use the SMTP backend.
228
+# Third-party backends can be specified by providing a Python path
229
+# to a module that defines an EmailBackend class.
230
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
231
+# Host for sending email.
232
+EMAIL_HOST = 'smtp.exmail.qq.com'
233
+# Port for sending email.
234
+EMAIL_PORT = 25
235
+# Optional SMTP authentication information for EMAIL_HOST.
236
+EMAIL_HOST_USER = 'error.notify@exmail.com'
237
+EMAIL_HOST_PASSWORD = '<^_^>pwd<^_^>'
238
+EMAIL_USE_TLS = False
239
+EMAIL_USE_SSL = False
240
+EMAIL_SSL_CERTFILE = None
241
+EMAIL_SSL_KEYFILE = None
242
+EMAIL_TIMEOUT = None
243
+# Default email address to use for various automated correspondence from
244
+# the site managers.
245
+DEFAULT_FROM_EMAIL = 'error.notify <error.notify@exmail.com>'
246
+# People who get code error notifications.
247
+# In the format [('Full Name', 'email@example.com'), ('Full Name', 'anotheremail@example.com')]
248
+ADMINS = [('Zhang San', 'san.zhang@exmail.com'), ('Li Si', 'si.li@exmail.com')]
249
+# Not-necessarily-technical managers of the site. They get broken link
250
+# notifications and other various emails.
251
+MANAGERS = ADMINS
252
+# Subject-line prefix for email messages send with django.core.mail.mail_admins
253
+# or ...mail_managers.  Make sure to include the trailing space.
254
+EMAIL_SUBJECT_PREFIX = u'[Kodo] '
255
+
256
+# Admin Settings
257
+DISABLE_ACTION = False
258
+
259
+# 开发调试相关配置
260
+if DEBUG:
261
+    try:
262
+        from local_settings_dev import *
263
+    except ImportError:
264
+        pass
265
+
266
+try:
267
+    from local_settings import *
268
+except ImportError:
269
+    pass
270
+
271
+try:
272
+    from oauth_settings import *
273
+except ImportError:
274
+    pass
275
+
276
+# 依赖 local_settings 中的配置
277
+# 微信授权设置
278
+# WECHAT_OAUTH2_REDIRECT_URI = '{0}/we/oauth2?scope={{0}}&redirect_url={{1}}'.format(DOMAIN)
279
+# Shorten URL
280
+# ``o`` is short for oauth2
281
+# ``r`` is short for redirect_url
282
+WECHAT_OAUTH2_REDIRECT_URI = '{0}/we/o?scope={{0}}&r={{1}}'.format(DOMAIN)
283
+WECHAT_OAUTH2_USERINFO_REDIRECT_URI = '{0}/we/o?r={{0}}'.format(DOMAIN)  # Scope default snsapi_userinfo
284
+WECHAT_BASE_REDIRECT_URI = '{0}/we/base_redirect'.format(DOMAIN)
285
+WECHAT_USERINFO_REDIRECT_URI = '{0}/we/userinfo_redirect'.format(DOMAIN)
286
+WECHAT_DIRECT_BASE_REDIRECT_URI = '{0}/we/direct_base_redirect'.format(DOMAIN)
287
+WECHAT_DIRECT_USERINFO_REDIRECT_URI = '{0}/we/direct_userinfo_redirect'.format(DOMAIN)
288
+
289
+try:
290
+    from func_settings import redis_connect
291
+    REDIS_CACHE = redis_connect(REDIS.get('default', {}))
292
+except ImportError:
293
+    REDIS_CACHE = None
294
+
295
+# LOGGER 设置
296
+LOGGING = {
297
+    'version': 1,
298
+    'disable_existing_loggers': False,
299
+    'formatters': {
300
+        'verbose': {
301
+            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
302
+        },
303
+        'simple': {
304
+            'format': '%(levelname)s %(message)s'
305
+        },
306
+    },
307
+    'handlers': {
308
+        'console': {
309
+            'level': 'DEBUG',
310
+            'class': 'logging.StreamHandler',
311
+            'formatter': 'verbose'
312
+        },
313
+    },
314
+    'loggers': {
315
+        'console': {
316
+            'handlers': ['console'],
317
+            'level': 'DEBUG',
318
+            'propagate': True,
319
+        },
320
+    },
321
+}

+ 574 - 0
kodo/static/templet/js/jswe.js

@@ -0,0 +1,574 @@
1
+!(function(e, t) {
2
+    var config = {
3
+        wxconfig: 'http://api.tt4it.com/wx/jsapi_signature',
4
+        callback: 'callback'
5
+    }, wxData = {
6
+        debug: false,
7
+        imgUrl: '',
8
+        link: '',
9
+        desc: '',
10
+        title: '',
11
+        timeLine: ''
12
+    }, wxConfig = {
13
+        hide: false,
14
+        baseFlag: false,
15
+        baseHide: false,
16
+        close: false,
17
+        hideMenuItems: [],
18
+        showMenuItems: []
19
+    }, jsApiList = [
20
+        'checkJsApi',
21
+        'onMenuShareTimeline',
22
+        'onMenuShareAppMessage',
23
+        'onMenuShareQQ',
24
+        'onMenuShareWeibo',
25
+        'onMenuShareQZone',
26
+        'hideMenuItems',
27
+        'showMenuItems',
28
+        'hideAllNonBaseMenuItem',
29
+        'showAllNonBaseMenuItem',
30
+        'translateVoice',
31
+        'startRecord',
32
+        'stopRecord',
33
+        'onRecordEnd',
34
+        'playVoice',
35
+        'pauseVoice',
36
+        'stopVoice',
37
+        'uploadVoice',
38
+        'downloadVoice',
39
+        'chooseImage',
40
+        'previewImage',
41
+        'uploadImage',
42
+        'downloadImage',
43
+        'getLocalImgData',
44
+        'getNetworkType',
45
+        'openLocation',
46
+        'getLocation',
47
+        'hideOptionMenu',
48
+        'showOptionMenu',
49
+        'closeWindow',
50
+        'scanQRCode',
51
+        'chooseWXPay',
52
+        'openEnterpriseRedPacket',
53
+        'openProductSpecificView',
54
+        'addCard',
55
+        'chooseCard',
56
+        'openCard'
57
+    ], wxApiFun
58
+
59
+    function isEmpty(obj) {
60
+        if (obj == null) return true
61
+        if (obj.length > 0) return false
62
+        if (obj.length === 0) return true
63
+        for (var key in obj) {
64
+            if (Object.prototype.hasOwnProperty.call(obj, key)) return false
65
+        }
66
+        return true
67
+    }
68
+
69
+    function isNotEmpty(obj) {
70
+        return !isEmpty(obj)
71
+    }
72
+
73
+    function isOpenOnPC() {  // 判断当前网页是否在 PC 浏览器中打开
74
+        var ua = navigator.userAgent
75
+        return /windows nt/i.test(ua) || /macintosh/i.test(ua) || /linux x86_64/i.test(ua)
76
+    }
77
+
78
+    function isOpenInWeixin() {  // 判断当前网页是否在微信内置浏览器中打开
79
+        return /micromessenger/i.test(navigator.userAgent)
80
+    }
81
+
82
+    function getWeixinVersion() {
83
+        var ua = navigator.userAgent,
84
+            mt = ua.match(/micromessenger\/([\d.]+)/i)
85
+        return (mt ? mt[1] : '')
86
+    }
87
+
88
+    // This function checks whether Wechat is the appointed version or not
89
+    // Cmp: http://jsperf.com/regexp-test-vs-indexof-ignore-upper-and-lower
90
+    function isWeixinVersion(version) {
91
+        // return new RegExp('micromessenger/' + version , 'i').test(navigator.userAgent)
92
+        return navigator.userAgent.toLowerCase().indexOf('micromessenger/' + version) != -1
93
+    }
94
+
95
+    function hideOptionMenu() {
96
+        wxConfig.hide = true
97
+        fixedWxData()
98
+    }
99
+
100
+    function showOptionMenu() {
101
+        wxConfig.hide = false
102
+        fixedWxData()
103
+    }
104
+
105
+    function hideMenuItems(items) {
106
+        wxConfig.hideMenuItems = items
107
+        fixedWxData()
108
+    }
109
+
110
+    function showMenuItems(items) {
111
+        wxConfig.showMenuItems = items
112
+        fixedWxData()
113
+    }
114
+
115
+    function hideAllNonBaseMenuItem() {
116
+        wxConfig.baseFlag = true
117
+        wxConfig.baseHide = true
118
+        fixedWxData()
119
+    }
120
+
121
+    function showAllNonBaseMenuItem() {
122
+        wxConfig.baseFlag = true
123
+        wxConfig.baseHide = false
124
+        fixedWxData()
125
+    }
126
+
127
+    function closeWindow() {
128
+        wxConfig.close = true
129
+        fixedWxData()
130
+    }
131
+
132
+    function wxReady(data) {
133
+        data = typeof data === 'object' ? data : JSON.parse(data)
134
+        wx.config({
135
+            debug: wxData.debug,
136
+            appId: data.appId,
137
+            timestamp: data.timestamp,
138
+            nonceStr: data.nonceStr,
139
+            signature: data.signature,
140
+            jsApiList: jsApiList
141
+        })
142
+
143
+        var callbacks = {
144
+            trigger: function (res) {
145
+                // alert('用户点击发送给朋友')
146
+                if (JSWE.wxTrigger) {JSWE.wxTrigger(res)}
147
+            },
148
+            success: function (res) {
149
+                // alert('已分享')
150
+                if (JSWE.wxSuccess) {JSWE.wxSuccess(res)}
151
+            },
152
+            cancel: function (res) {
153
+                // alert('已取消')
154
+                if (JSWE.wxCancel) {JSWE.wxCancel(res)}
155
+            },
156
+            fail: function (res) {
157
+                // alert(JSON.stringify(res))
158
+                if (JSWE.wxFail) {JSWE.wxFail(res)}
159
+            }
160
+        }, shareInfo = function(flag) {
161
+            var _share = {
162
+                title: flag ? wxData.title : (wxData.timeLine || wxData.desc),
163
+                link: wxData.link,
164
+                imgUrl: wxData.imgUrl,
165
+                trigger: callbacks.trigger,
166
+                success: callbacks.success,
167
+                cancel: callbacks.cancel,
168
+                fail: callbacks.fail
169
+            }
170
+            if (flag) _share.desc = wxData.desc
171
+            return _share
172
+        }, wxShareApi = function() {
173
+            // 2. 分享接口
174
+            // 2.1 监听“分享给朋友”,按钮点击、自定义分享内容及分享结果接口
175
+            wx.onMenuShareAppMessage(shareInfo(1))
176
+            // 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
177
+            wx.onMenuShareTimeline(shareInfo(0))
178
+            // 2.3 监听“分享到QQ”按钮点击、自定义分享内容及分享结果接口
179
+            wx.onMenuShareQQ(shareInfo(1))
180
+            // 2.4 监听“分享到微博”按钮点击、自定义分享内容及分享结果接口
181
+            wx.onMenuShareWeibo(shareInfo(1))
182
+            // 2.5 监听“分享到QQ空间”按钮点击、自定义分享内容及分享结果接口
183
+            wx.onMenuShareQZone(shareInfo(1))
184
+        }, wxMenuApi = function () {
185
+            // 8. 界面操作接口
186
+            // 8.1 隐藏右上角菜单
187
+            // 8.2 显示右上角菜单
188
+            if (wxConfig.hide) {wx.hideOptionMenu()} else {wx.showOptionMenu()}
189
+            // 8.3 批量隐藏菜单项
190
+            if (isNotEmpty(wxConfig.hideMenuItems)) {
191
+                wx.hideMenuItems({
192
+                    menuList: wxConfig.hideMenuItems,
193
+                    success: function (res) {
194
+                        if (JSWE.wxHideMenuItemsSuccess) {JSWE.wxHideMenuItemsSuccess(res)}
195
+                    },
196
+                    fail: function (res) {
197
+                        if (JSWE.wxHideMenuItemsFail) {JSWE.wxHideMenuItemsFail(res)}
198
+                    }
199
+                })
200
+            }
201
+            // 8.4 批量显示菜单项
202
+            if (isNotEmpty(wxConfig.showMenuItems)) {
203
+                wx.showMenuItems({
204
+                    menuList: wxConfig.showMenuItems,
205
+                    success: function (res) {
206
+                        if (JSWE.wxShowMenuItemsSuccess) {JSWE.wxShowMenuItemsSuccess(res)}
207
+                    },
208
+                    fail: function (res) {
209
+                        if (JSWE.wxShowMenuItemsFail) {JSWE.wxShowMenuItemsFail(res)}
210
+                    }
211
+                })
212
+            }
213
+            // 8.5 隐藏所有非基本菜单项
214
+            // 8.6 显示所有被隐藏的非基本菜单项
215
+            if (wxConfig.baseFlag) {
216
+                if (wxConfig.baseHide) {wx.hideAllNonBaseMenuItem()} else {wx.showAllNonBaseMenuItem()}
217
+            }
218
+            // 8.7 关闭当前窗口
219
+            if (wxConfig.close) {wx.closeWindow()}
220
+        }, wxVoiceApi = function() {
221
+            // 4.3 监听录音自动停止
222
+            wx.onVoiceRecordEnd({
223
+                complete: function (res) {
224
+                    voice.localId = res.localId
225
+                    if (JSWE.wxVoiceRecordEnd) {JSWE.wxVoiceRecordEnd(res)}
226
+                }
227
+            })
228
+            // 4.7 监听录音播放停止
229
+            wx.onVoicePlayEnd({
230
+                complete: function (res) {
231
+                    if (JSWE.wxVoicePlayEnd) {JSWE.wxVoicePlayEnd(res)}
232
+                }
233
+            })
234
+        }, wxApi = function () {
235
+            wxShareApi()
236
+            wxMenuApi()
237
+            wxVoiceApi()
238
+        }
239
+
240
+        wx.ready(wxApi)
241
+
242
+        return wxApiFun = wxApi
243
+    }
244
+
245
+    if (isOpenInWeixin() || isOpenOnPC()) {
246
+        if ('undefined' !== typeof JSWE_CONF_UPDATE) JSWE_CONF_UPDATE(config)
247
+        $.ajax({
248
+            url: config.wxconfig,
249
+            type: 'get',
250
+            dataType: 'jsonp',
251
+            jsonpCallback: config.callback,
252
+            data: {
253
+                url: window.location.href.split('#')[0]
254
+            },
255
+            success: wxReady
256
+        })
257
+    }
258
+
259
+    function initWxData(data, flag) {
260
+        for(var d in data) {if (d in wxData) wxData[d] = data[d]}
261
+        if (flag) fixedWxData()
262
+    }
263
+
264
+    function changeWxData(key, value, flag) {
265
+        if (key in falDwxDataata) {wxData[key] = value}
266
+        if (flag) fixedWxData()
267
+    }
268
+
269
+    function fixedWxData() {
270
+        if ('undefined' !== typeof wxApiFun) wxApiFun()
271
+    }
272
+
273
+    // 3 智能接口
274
+    var voice = {
275
+        localId: '',
276
+        serverId: ''
277
+    }
278
+    // 3.1 识别音频并返回识别结果
279
+    function translateVoice() {
280
+        if (voice.localId == '') {
281
+            if (JSWE.wxTranslateVoiceEmpty) {JSWE.wxTranslateVoiceEmpty()}
282
+            return
283
+        }
284
+        wx.translateVoice({
285
+            localId: voice.localId,
286
+            complete: function (res) {
287
+                if (JSWE.wxTranslateVoiceComplete) {JSWE.wxTranslateVoiceComplete(res)}
288
+            }
289
+        })
290
+    }
291
+
292
+    // 4 音频接口
293
+    // 4.1 开始录音
294
+    function startRecord() {
295
+        wx.startRecord({
296
+            cancel: function () {
297
+                if (JSWE.wxStartRecordCancel) {JSWE.wxStartRecordCancel(res)}
298
+            }
299
+        })
300
+    }
301
+
302
+    // 4.2 停止录音
303
+    function stopRecord() {
304
+        wx.stopRecord({
305
+          success: function (res) {
306
+              voice.localId = res.localId
307
+              if (JSWE.wxStopRecordSuccess) {JSWE.wxStopRecordSuccess(res)}
308
+          },
309
+          fail: function (res) {
310
+              if (JSWE.wxStopRecordFail) {JSWE.wxStopRecordFail(res)}
311
+          }
312
+        })
313
+    }
314
+
315
+    // 4.4 播放音频
316
+    function playVoice() {
317
+        if (voice.localId == '') {
318
+            if (JSWE.wxPlayVoiceEmpty) {JSWE.wxPlayVoiceEmpty()}
319
+            return
320
+        }
321
+        wx.playVoice({
322
+            localId: voice.localId
323
+        })
324
+    }
325
+
326
+    // 4.5 暂停播放音频
327
+    function pauseVoice() {
328
+        if (voice.localId == '') {
329
+            if (JSWE.wxPauseVoiceEmpty) {JSWE.wxPauseVoiceEmpty()}
330
+            return
331
+        }
332
+        wx.pauseVoice({
333
+            localId: voice.localId
334
+        })
335
+    }
336
+
337
+    // 4.6 停止播放音频
338
+    function stopVoice() {
339
+        if (voice.localId == '') {
340
+            if (JSWE.wxStopVoiceEmpty) {JSWE.wxStopVoiceEmpty()}
341
+            return
342
+        }
343
+        wx.stopVoice({
344
+            localId: voice.localId
345
+        })
346
+    }
347
+
348
+    // 4.8 上传语音
349
+    function uploadVoice() {
350
+        var localId = voice.localId
351
+        if (localId == '') {
352
+            if (JSWE.wxUploadVoiceEmpty) {JSWE.wxUploadVoiceEmpty()}
353
+            return
354
+        }
355
+        wx.uploadVoice({
356
+            localId: localId,
357
+            success: function (res) {
358
+                voice.serverId = res.serverId
359
+                if (JSWE.wxUploadVoiceSuccess) {JSWE.wxUploadVoiceSuccess(res, localId)}
360
+            }
361
+        })
362
+    }
363
+
364
+    // 4.9 下载语音
365
+    function downloadVoice() {
366
+        var serverId = voice.serverId
367
+        if (serverId == '') {
368
+            if (JSWE.wxDownloadVoiceEmpty) {JSWE.wxDownloadVoiceEmpty()}
369
+            return
370
+        }
371
+        wx.downloadVoice({
372
+            serverId: serverId,
373
+            success: function (res) {
374
+                voice.localId = res.localId
375
+                if (JSWE.wxDownloadVoiceSuccess) {JSWE.wxDownloadVoiceSuccess(res, serverId)}
376
+            }
377
+        })
378
+    }
379
+
380
+    // 5 图片接口
381
+    var images = {
382
+        localIds: [],
383
+        serverIds: []
384
+    }
385
+    // 5.1 拍照、本地选图
386
+    function chooseImage(choose_params) {
387
+        if ('undefined' === typeof choose_params) choose_params = {}
388
+        wx.chooseImage({
389
+            count: choose_params.count || 9, // 默认9
390
+            sizeType: choose_params.sizeType || ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
391
+            sourceType: choose_params.sourceType || ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
392
+            success: function (res) {
393
+                images.localIds = res.localIds // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
394
+                // 判断是否直接上传
395
+                if (choose_params.directUpload) {setTimeout(uploadImages({localIds: images.localIds, isShowProgressTips: choose_params.isShowProgressTips || 1}), 100)}
396
+                // 拍照、本地选图成功后的回调函数
397
+                if (JSWE.wxChooseImageSuccess) {JSWE.wxChooseImageSuccess(res, choose_params.extras || {})}
398
+            }
399
+        })
400
+    }
401
+
402
+    // 5.2 图片预览
403
+    function previewImage(preview_params) {
404
+        wx.previewImage({
405
+            current: preview_params.current, // 当前显示图片的链接,不填则默认为 urls 的第一张
406
+            urls: preview_params.urls // 需要预览的图片链接列表
407
+        })
408
+    }
409
+
410
+    // 5.3 上传图片
411
+    function uploadImage(upload_params) {
412
+        // 上传图片为异步处理,重复上传同一图片,返回的serverId也是不同的
413
+        var localId = upload_params.localId
414
+        wx.uploadImage({
415
+            localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
416
+            isShowProgressTips: upload_params.isShowProgressTips || 1, // 默认为1,显示进度提示
417
+            success: function (res) {
418
+                images.serverIds.push(res.serverId) // 返回图片的服务器端ID
419
+                // 上传图片成功后的回调函数
420
+                if (JSWE.wxUploadImageSuccess) {JSWE.wxUploadImageSuccess(res, localId)}
421
+            }
422
+        })
423
+    }
424
+
425
+    function uploadImages(upload_params) {
426
+        var localIds = upload_params.localIds, isShowProgressTips = upload_params.isShowProgressTips || 1
427
+        images.serverIds = []
428
+        for (var idx in localIds) {uploadImage({localId: localIds[idx], isShowProgressTips: isShowProgressTips})}
429
+    }
430
+
431
+    // 5.4 下载图片
432
+    function downloadImage(download_params) {
433
+        var serverId = download_params.serverId
434
+        wx.downloadImage({
435
+            serverId: serverId, // 需要下载的图片的服务器端ID,由uploadImage接口获得
436
+            isShowProgressTips: download_params.isShowProgressTips || 1, // 默认为1,显示进度提示
437
+            success: function (res) {
438
+                images.localId.push(res.localId)
439
+                if (JSWE.wxDownloadImageSuccess) {JSWE.wxDownloadImageSuccess(res, serverId)}
440
+            }
441
+        })
442
+    }
443
+
444
+    function downloadImages(download_params) {
445
+        var serverIds = download_params.serverIds, isShowProgressTips = download_params.isShowProgressTips || 1
446
+        images.localIds = []
447
+        for (var idx in serverIds) {downloadImage({serverId: serverIds[idx], isShowProgressTips: isShowProgressTips})}
448
+    }
449
+
450
+    function getLocalImgData(localId) {
451
+        wx.getLocalImgData({
452
+            localId: localId, // 图片的localID
453
+            success: function (res) {
454
+                // var localData = res.localData; // localData是图片的base64数据,可以用img标签显示
455
+                if (JSWE.wxGetLocalImgDataSuccess) {JSWE.wxGetLocalImgDataSuccess(res)}
456
+            }
457
+        })
458
+    }
459
+
460
+    // 9 微信原生接口
461
+    // 9.1.1 扫描二维码并返回结果
462
+    // 9.1.2 扫描二维码并返回结果
463
+    function scanQRCode(scan_params) {
464
+        if ('undefined' === typeof scan_params) scan_params = {}
465
+        wx.scanQRCode({
466
+            needResult: scan_params.needResult || 0,  // 默认为0,0扫描结果由微信处理,1直接返回扫描结果
467
+            scanType: scan_params.scanType || ['qrCode', 'barCode'],  // 可以指定扫二维码还是一维码,默认二者都有
468
+            success: function (res) {  // 当 needResult 为 1 时,扫码返回的结果
469
+                if (JSWE.wxScanQRCodeSuccess) {JSWE.wxScanQRCodeSuccess(res)}
470
+            }
471
+        })
472
+    }
473
+
474
+    // QRCode & BarCode is different
475
+    function parseScanQRCodeResultStr(resultStr) {
476
+        var strs = resultStr.split(',')
477
+        return strs[strs.length - 1]
478
+    }
479
+
480
+    // 10 微信支付接口
481
+    // 10.1 发起一个支付请求
482
+    function chooseWXPay(wxpay_params) {
483
+        wx.chooseWXPay({
484
+            timestamp: wxpay_params.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
485
+            nonceStr: wxpay_params.nonceStr, // 支付签名随机串,不长于 32 位
486
+            package: wxpay_params.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
487
+            signType: wxpay_params.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
488
+            paySign: wxpay_params.paySign, // 支付签名
489
+            success: function (res) {
490
+                // 支付成功后的回调函数
491
+                if (JSWE.wxPaySuccess) {JSWE.wxPaySuccess(res)}
492
+            }
493
+        })
494
+    }
495
+
496
+    // xx 微信原生企业红包接口
497
+    // xx.1 发起一个发送原生企业红包请求
498
+    function openEnterpriseRedPacket(wxredpack_params) {
499
+        wx.openEnterpriseRedPacket({
500
+            timeStamp: wxredpack_params.timeStamp, // 红包签名时间戳,注意原生企业红包接口timeStamp字段名需大写其中的S字符,而支付接口timeStamp字段名无需大写其中的S字符。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
501
+            nonceStr: wxredpack_params.nonceStr, // 红包签名随机串,不长于 32 位
502
+            package: encodeURIComponent(wxredpack_params.package), // 发放红包接口返回的prepay_id参数值,提交格式如:prepay_id=***)
503
+            signType: wxredpack_params.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
504
+            paySign: wxredpack_params.paySign, // 红包签名
505
+            success: function (res) {
506
+                // 发送原生企业红包成功后的回调函数
507
+                if (JSWE.wxEnterpriseRedPacketSuccess) {JSWE.wxEnterpriseRedPacketSuccess(res)}
508
+            }
509
+        })
510
+    }
511
+
512
+    var v = {
513
+        version: '1.0.5',
514
+
515
+        // Basic Vars
516
+        config: config,
517
+        wxData: wxData,
518
+        jsApiList: jsApiList,
519
+
520
+        isEmpty: isEmpty,
521
+        isNotEmpty: isNotEmpty,
522
+
523
+        // Weixin Function
524
+        isOpenInWeixin: isOpenInWeixin,
525
+        getWeixinVersion: getWeixinVersion,
526
+        isWeixinVersion: isWeixinVersion,
527
+
528
+        // Menu Function
529
+        hideOptionMenu: hideOptionMenu,
530
+        showOptionMenu: showOptionMenu,
531
+        hideMenuItems: hideMenuItems,
532
+        showMenuItems: showMenuItems,
533
+        hideAllNonBaseMenuItem: hideAllNonBaseMenuItem,
534
+        showAllNonBaseMenuItem: showAllNonBaseMenuItem,
535
+        closeWindow: closeWindow,
536
+
537
+        // Share Function
538
+        initWxData: initWxData,
539
+        changeWxData: changeWxData,
540
+        fixedWxData: fixedWxData,
541
+
542
+        // Voice Function
543
+        voice: voice,
544
+        translateVoice: translateVoice,
545
+        startRecord: startRecord,
546
+        stopRecord: stopRecord,
547
+        playVoice: playVoice,
548
+        pauseVoice: pauseVoice,
549
+        stopVoice: stopVoice,
550
+        uploadVoice: uploadVoice,
551
+        downloadVoice: downloadVoice,
552
+
553
+        // Image Function
554
+        images: images,
555
+        chooseImage: chooseImage,
556
+        previewImage: previewImage,
557
+        uploadImage: uploadImage,
558
+        uploadImages: uploadImages,
559
+        downloadImage: downloadImage,
560
+        downloadImages: downloadImages,
561
+        getLocalImgData: getLocalImgData,
562
+
563
+        // Scan Function
564
+        scanQRCode: scanQRCode,
565
+        parseScanQRCodeResultStr: parseScanQRCodeResultStr,
566
+
567
+        // Pay Function
568
+        chooseWXPay: chooseWXPay,
569
+
570
+        // EnterpriseRedPacket Function
571
+        openEnterpriseRedPacket: openEnterpriseRedPacket
572
+    }
573
+    e.JSWE = e.V = v
574
+})(window)

+ 5 - 0
kodo/templates/admin/view.html

@@ -0,0 +1,5 @@
1
+{% extends "admin/change_form.html" %}
2
+{% load i18n %}
3
+
4
+{% block submit_buttons_bottom %}
5
+{% endblock %}

+ 36 - 0
kodo/urls.py

@@ -0,0 +1,36 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+"""kodo URL Configuration
4
+
5
+The `urlpatterns` list routes URLs to views. For more information please see:
6
+    https://docs.djangoproject.com/en/1.11/topics/http/urls/
7
+Examples:
8
+Function views
9
+    1. Add an import:  from my_app import views
10
+    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
11
+Class-based views
12
+    1. Add an import:  from other_app.views import Home
13
+    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
14
+Including another URLconf
15
+    1. Import the include() function: from django.conf.urls import url, include
16
+    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
17
+"""
18
+from django.conf import settings
19
+from django.conf.urls import include, url
20
+from django.conf.urls.static import static
21
+from django.contrib import admin
22
+
23
+
24
+urlpatterns = [
25
+    url(r'^admin/', admin.site.urls),
26
+    url(r'^api/', include('api.urls', namespace='api')),
27
+    # url(r'^s/', include('django_short_url.urls', namespace='django_short_url')),
28
+    url(r'^uniapi/', include('django_uniapi.urls', namespace='uniapi')),
29
+    url(r'^we/', include('django_we.urls', namespace='wechat')),
30
+]
31
+
32
+urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
33
+urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
34
+
35
+# AdminSite
36
+admin.site.site_header = 'My administration'

+ 17 - 0
kodo/wsgi.py

@@ -0,0 +1,17 @@
1
+"""
2
+WSGI config for kodo project.
3
+
4
+It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+For more information on this file, see
7
+https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
8
+"""
9
+
10
+import os
11
+
12
+from django.core.wsgi import get_wsgi_application
13
+
14
+
15
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kodo.settings")
16
+
17
+application = get_wsgi_application()

+ 23 - 0
manage.py

@@ -0,0 +1,23 @@
1
+#!/usr/bin/env python
2
+import os
3
+import sys
4
+
5
+
6
+if __name__ == "__main__":
7
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kodo.settings")
8
+    try:
9
+        from django.core.management import execute_from_command_line
10
+    except ImportError:
11
+        # The above import may fail for some other reason. Ensure that the
12
+        # issue is really that Django is missing to avoid masking other
13
+        # exceptions on Python 2.
14
+        try:
15
+            import django
16
+        except ImportError:
17
+            raise ImportError(
18
+                "Couldn't import Django. Are you sure it's installed and "
19
+                "available on your PYTHONPATH environment variable? Did you "
20
+                "forget to activate a virtual environment?"
21
+            )
22
+        raise
23
+    execute_from_command_line(sys.argv)

+ 0 - 0
mch/__init__.py


+ 22 - 0
mch/admin.py

@@ -0,0 +1,22 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django.contrib import admin
4
+
5
+from mch.models import BrandInfo, DistributorInfo, ModelInfo
6
+
7
+
8
+class BrandInfoAdmin(admin.ModelAdmin):
9
+    list_display = ('brand_id', 'brand_name', 'brand_descr', 'position', 'status', 'created_at', 'updated_at')
10
+
11
+
12
+class ModelInfoAdmin(admin.ModelAdmin):
13
+    list_display = ('model_id', 'model_name', 'model_descr', 'position', 'status', 'created_at', 'updated_at')
14
+
15
+
16
+class DistributorInfoAdmin(admin.ModelAdmin):
17
+    list_display = ('distributor_id', 'distributor_name', 'distributor_descr', 'position', 'status', 'created_at', 'updated_at')
18
+
19
+
20
+admin.site.register(BrandInfo, BrandInfoAdmin)
21
+admin.site.register(ModelInfo, ModelInfoAdmin)
22
+admin.site.register(DistributorInfo, DistributorInfoAdmin)

+ 8 - 0
mch/apps.py

@@ -0,0 +1,8 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.apps import AppConfig
5
+
6
+
7
+class MchConfig(AppConfig):
8
+    name = 'mch'

+ 68 - 0
mch/migrations/0001_initial.py

@@ -0,0 +1,68 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.3 on 2017-12-30 13:37
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+import shortuuidfield.fields
7
+
8
+
9
+class Migration(migrations.Migration):
10
+
11
+    initial = True
12
+
13
+    dependencies = [
14
+    ]
15
+
16
+    operations = [
17
+        migrations.CreateModel(
18
+            name='BrandInfo',
19
+            fields=[
20
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
22
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
23
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
24
+                ('brand_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u54c1\u724c\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
25
+                ('brand_name', models.CharField(blank=True, help_text='\u54c1\u724c\u540d\u79f0', max_length=255, null=True, verbose_name='brand_name')),
26
+                ('brand_descr', models.TextField(blank=True, help_text='\u54c1\u724c\u63cf\u8ff0', max_length=255, null=True, verbose_name='brand_descr')),
27
+                ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
28
+            ],
29
+            options={
30
+                'verbose_name': '\u54c1\u724c\u4fe1\u606f',
31
+                'verbose_name_plural': '\u54c1\u724c\u4fe1\u606f',
32
+            },
33
+        ),
34
+        migrations.CreateModel(
35
+            name='DistributorInfo',
36
+            fields=[
37
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
38
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
39
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
40
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
41
+                ('distributor_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u7ecf\u9500\u5546\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
42
+                ('distributor_name', models.CharField(blank=True, help_text='\u7ecf\u9500\u5546\u540d\u79f0', max_length=255, null=True, verbose_name='distributor_name')),
43
+                ('distributor_descr', models.TextField(blank=True, help_text='\u7ecf\u9500\u5546\u63cf\u8ff0', max_length=255, null=True, verbose_name='distributor_descr')),
44
+                ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
45
+            ],
46
+            options={
47
+                'verbose_name': '\u7ecf\u9500\u5546\u4fe1\u606f',
48
+                'verbose_name_plural': '\u7ecf\u9500\u5546\u4fe1\u606f',
49
+            },
50
+        ),
51
+        migrations.CreateModel(
52
+            name='ModelInfo',
53
+            fields=[
54
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
55
+                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
56
+                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
57
+                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
58
+                ('model_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u578b\u53f7\u552f\u4e00\u6807\u8bc6', max_length=22, unique=True)),
59
+                ('model_name', models.CharField(blank=True, help_text='\u578b\u53f7\u540d\u79f0', max_length=255, null=True, verbose_name='model_name')),
60
+                ('model_descr', models.TextField(blank=True, help_text='\u578b\u53f7\u63cf\u8ff0', max_length=255, null=True, verbose_name='model_descr')),
61
+                ('position', models.IntegerField(default=1, help_text='\u6392\u5e8f', verbose_name='position')),
62
+            ],
63
+            options={
64
+                'verbose_name': '\u578b\u53f7\u4fe1\u606f',
65
+                'verbose_name_plural': '\u578b\u53f7\u4fe1\u606f',
66
+            },
67
+        ),
68
+    ]

+ 0 - 0
mch/migrations/__init__.py


+ 75 - 0
mch/models.py

@@ -0,0 +1,75 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django.db import models
4
+from django.utils.translation import ugettext_lazy as _
5
+from models_ext import BaseModelMixin
6
+from shortuuidfield import ShortUUIDField
7
+
8
+
9
+class BrandInfo(BaseModelMixin):
10
+    brand_id = ShortUUIDField(_(u'brand_id'), max_length=32, help_text=u'品牌唯一标识', db_index=True, unique=True)
11
+    brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
12
+    brand_descr = models.TextField(_(u'brand_descr'), max_length=255, blank=True, null=True, help_text=u'品牌描述')
13
+
14
+    position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
15
+
16
+    class Meta:
17
+        verbose_name = _(u'品牌信息')
18
+        verbose_name_plural = _(u'品牌信息')
19
+
20
+    def __unicode__(self):
21
+        return unicode(self.pk)
22
+
23
+    @property
24
+    def data(self):
25
+        return {
26
+            'brand_id': self.brand_id,
27
+            'brand_name': self.brand_name,
28
+            'brand_descr': self.brand_descr,
29
+        }
30
+
31
+
32
+class ModelInfo(BaseModelMixin):
33
+    model_id = ShortUUIDField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True, unique=True)
34
+    model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
35
+    model_descr = models.TextField(_(u'model_descr'), max_length=255, blank=True, null=True, help_text=u'型号描述')
36
+
37
+    position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
38
+
39
+    class Meta:
40
+        verbose_name = _(u'型号信息')
41
+        verbose_name_plural = _(u'型号信息')
42
+
43
+    def __unicode__(self):
44
+        return unicode(self.pk)
45
+
46
+    @property
47
+    def data(self):
48
+        return {
49
+            'model_id': self.model_id,
50
+            'model_name': self.model_name,
51
+            'model_descr': self.model_descr,
52
+        }
53
+
54
+
55
+class DistributorInfo(BaseModelMixin):
56
+    distributor_id = ShortUUIDField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True, unique=True)
57
+    distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
58
+    distributor_descr = models.TextField(_(u'distributor_descr'), max_length=255, blank=True, null=True, help_text=u'经销商描述')
59
+
60
+    position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
61
+
62
+    class Meta:
63
+        verbose_name = _(u'经销商信息')
64
+        verbose_name_plural = _(u'经销商信息')
65
+
66
+    def __unicode__(self):
67
+        return unicode(self.pk)
68
+
69
+    @property
70
+    def data(self):
71
+        return {
72
+            'distributor_id': self.distributor_id,
73
+            'distributor_name': self.distributor_name,
74
+            'distributor_descr': self.distributor_descr,
75
+        }

+ 7 - 0
mch/tests.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.test import TestCase
5
+
6
+
7
+# Create your tests here.

+ 7 - 0
mch/views.py

@@ -0,0 +1,7 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.shortcuts import render
5
+
6
+
7
+# Create your views here.

+ 9 - 0
pep8.sh

@@ -0,0 +1,9 @@
1
+#!/bin/bash
2
+
3
+# Ignoring autogenerated files
4
+#  -- Migration directories
5
+# Ignoring error codes
6
+#  -- E128 continuation line under-indented for visual indent
7
+#  -- E501 line too long
8
+
9
+pycodestyle --exclude=build,migrations,.tox --ignore=E128,E501 .

+ 18 - 0
requirements.txt

@@ -0,0 +1,18 @@
1
+Django==1.11.3
2
+StatusCode==1.0.0
3
+django-admin==1.1.0
4
+django-detect==1.0.5
5
+django-json-render==1.0.0
6
+django-json-response==1.1.5
7
+django-models-ext==1.0.5
8
+django-short-url==1.0.2
9
+django-uniapi==1.0.0
10
+django-we==1.1.2
11
+furl==1.0.1
12
+hiredis==0.2.0
13
+mysqlclient==1.3.12
14
+pywe-oauth==1.0.5
15
+pywe-pay==1.0.11
16
+redis==2.10.6
17
+redis-extensions==1.1.6
18
+rsa==3.4.2

+ 0 - 0
utils/__init__.py


+ 0 - 0
utils/algorithm/__init__.py


+ 13 - 0
utils/algorithm/b64.py

@@ -0,0 +1,13 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import base64
4
+
5
+from CodeConvert import CodeConvert as cc
6
+
7
+
8
+def b64_encrypt(plaintext):
9
+    return base64.urlsafe_b64encode(cc.Convert2Utf8(plaintext))
10
+
11
+
12
+def b64_decrypt(ciphertext):
13
+    return cc.Convert2Unicode(base64.urlsafe_b64decode(ciphertext))

+ 18 - 0
utils/algorithm/rsalg.py

@@ -0,0 +1,18 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import base64
4
+
5
+import rsa
6
+from CodeConvert import CodeConvert as cc
7
+
8
+
9
+pubkey = rsa.PublicKey(7733936986002684982484845608354489436048239676995253266549456282870195715569430535348099548536388503919509506510435040149560886821029985877148893951171111, 65537)
10
+privkey = rsa.PrivateKey(7733936986002684982484845608354489436048239676995253266549456282870195715569430535348099548536388503919509506510435040149560886821029985877148893951171111, 65537, 316971401565576878144472516350155768882090601834219605321449556369521730928872332388800749109622843453327077688969025635980606763507018292148749534091473, 4517492317789178911663214752269837474466539823144998211438927363654134055916886851, 1711997816918835594017245862832442114582648667392542139046338517030653261)
11
+
12
+
13
+def rsa_encrypt(plaintext):
14
+    return base64.urlsafe_b64encode(rsa.encrypt(cc.Convert2Utf8(plaintext), pubkey))
15
+
16
+
17
+def rsa_decrypt(ciphertext):
18
+    return rsa.decrypt(base64.urlsafe_b64decode(cc.Convert2Utf8(ciphertext)), privkey)

+ 0 - 0
utils/error/__init__.py


+ 72 - 0
utils/error/errno_utils.py

@@ -0,0 +1,72 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from StatusCode import BaseStatusCode, StatusCodeField
4
+
5
+
6
+class ProfileStatusCode(BaseStatusCode):
7
+    """ 4001xx 用户相关错误码 """
8
+    PROFILE_NOT_FOUND = StatusCodeField(400101, 'Profile Not Found', description=u'用户不存在')
9
+
10
+
11
+class PhoneStatusCode(BaseStatusCode):
12
+    """ 4002xx 手机相关错误码 """
13
+    INVALID_PHONE = StatusCodeField(400200, 'Invalid Phone', description=u'非法手机号')
14
+    PHONE_NOT_FOUND = StatusCodeField(400201, 'Phone Not Found', description=u'手机号不存在')
15
+    PHONE_ALREADY_EXISTS = StatusCodeField(400202, 'Phone Already Exists', description=u'手机号已存在')
16
+
17
+
18
+class OrderStatusCode(BaseStatusCode):
19
+    """ 4040xx 订单/支付相关错误码 """
20
+    UNIFIED_ORDER_FAIL = StatusCodeField(404000, 'Unified Order Fail', description=u'统一下单失败')
21
+    ORDER_NOT_FOUND = StatusCodeField(404001, 'Order Not Found', description=u'订单不存在')
22
+    # 订单支付状态
23
+    ORDER_NOT_PAY = StatusCodeField(404011, 'Order Not Pay', description=u'订单未支付')
24
+    ORDER_PAYING = StatusCodeField(404012, 'Order Paying', description=u'订单支付中')
25
+    ORDER_PAY_FAIL = StatusCodeField(404013, 'Order Pay Fail', description=u'微信支付失败')
26
+    # 通知校验状态
27
+    SIGN_CHECK_FAIL = StatusCodeField(404090, 'Sign Check Fail', description=u'签名校验失败')
28
+    FEE_CHECK_FAIL = StatusCodeField(404091, 'FEE Check Fail', description=u'金额校验失败')
29
+
30
+
31
+class PayStatusCode(BaseStatusCode):
32
+    """ 4041xx 支付相关错误码 """
33
+
34
+
35
+class WithdrawStatusCode(BaseStatusCode):
36
+    """ 4042xx 提现相关错误码 """
37
+    BALANCE_INSUFFICIENT = StatusCodeField(404200, 'Balance Insufficient', description=u'提现金额不足')
38
+
39
+
40
+class TokenStatusCode(BaseStatusCode):
41
+    """ 4090xx 票据相关错误码 """
42
+    TOKEN_NOT_FOUND = StatusCodeField(409001, 'Token Not Found', description=u'票据不存在')
43
+
44
+
45
+class SignatureStatusCode(BaseStatusCode):
46
+    """ 4091xx 签名校验错误 """
47
+    SIGNATURE_ERROR = StatusCodeField(409101, 'Signature Error', description=u'签名错误')
48
+
49
+
50
+class GVCodeStatusCode(BaseStatusCode):
51
+    """ 4095xx 图形验证码相关错误码 """
52
+    GRAPHIC_VCODE_ERROR = StatusCodeField(409101, 'Graphic VCode Error', description=u'图形验证码错误')
53
+
54
+
55
+class SVCodeStatusCode(BaseStatusCode):
56
+    """ 4092xx 短信验证码相关错误码 """
57
+    SMS_QUOTA_LIMIT = StatusCodeField(409200, 'SMS Quota Limit', description=u'短信次数超限')
58
+    SMS_VCODE_ERROR = StatusCodeField(409201, 'SMS VCode Error', description=u'验证码错误,请稍后重试')
59
+    SMS_VCODE_HAS_SEND = StatusCodeField(409202, 'SMS VCode Has Send', description=u'验证码已发送,请勿重复获取')
60
+
61
+
62
+class InsufficientStatusCode(BaseStatusCode):
63
+    """ 4095xx 不足相关错误码 """
64
+    BALANCE_INSUFFICIENT = StatusCodeField(409501, 'Balance Insufficient', description=u'余额不足')
65
+    INTEGRAL_INSUFFICIENT = StatusCodeField(409502, 'Integral Insufficient', description=u'积分不足')
66
+
67
+
68
+class PermissionStatusCode(BaseStatusCode):
69
+    """ 4099xx 权限相关错误码 """
70
+    PERMISSION_DENIED = StatusCodeField(409900, 'Permission Denied', description=u'权限不足')
71
+    UPLOAD_PERMISSION_DENIED = StatusCodeField(409910, 'Upload Permission Denied', description=u'上传权限不足')
72
+    UPDATE_PERMISSION_DENIED = StatusCodeField(409930, 'Update Permission Denied', description=u'更新权限不足')

+ 18 - 0
utils/error/response_utils.py

@@ -0,0 +1,18 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django.http import JsonResponse
4
+from StatusCode import StatusCodeField
5
+
6
+
7
+def response_data(status_code=200, message=None, description=None, data={}, **kwargs):
8
+    return dict({
9
+        'status': status_code,
10
+        'message': message,
11
+        'description': description,
12
+        'data': data,
13
+    }, **kwargs)
14
+
15
+
16
+def response(status_code=200, message=None, description=None, data={}, **kwargs):
17
+    message, description = (message or status_code.message, description or status_code.description) if isinstance(status_code, StatusCodeField) else (message, description)
18
+    return JsonResponse(response_data(status_code, message, description, data, **kwargs), safe=False)

+ 0 - 0
utils/redis/__init__.py


+ 6 - 0
utils/redis/connect.py

@@ -0,0 +1,6 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django.conf import settings
4
+
5
+
6
+r = settings.REDIS_CACHE

+ 1 - 0
utils/redis/rkeys.py

@@ -0,0 +1 @@
1
+# -*- coding: utf-8 -*-

+ 0 - 0
utils/user/__init__.py


+ 18 - 0
utils/user/userinfo_save.py

@@ -0,0 +1,18 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+
4
+def userinfo_save(userinfo):
5
+    """ Save profile or something else """
6
+    # from account.models import UserInfo
7
+    # from django.conf import settings
8
+    #
9
+    # unique_identifier = userinfo.get(settings.WECHAT_UNIQUE_IDENTIFICATION, '')
10
+    #
11
+    # user, created = UserInfo.objects.select_for_update().get_or_create(**{settings.WECHAT_UNIQUE_IDENTIFICATION: unique_identifier})
12
+    # user.unionid = userinfo.get('unionid', '')
13
+    # user.openid = userinfo.get('openid', '')
14
+    # user.nickname = userinfo.get('nickname', '')
15
+    # user.avatar = userinfo.get('headimgurl', '')
16
+    # user.save()
17
+    #
18
+    # return user

add src for LatestAppInfo/SplashInfo · 27d3ec8fb1 - Gogs: Go Git Service

add src for LatestAppInfo/SplashInfo

Brightcells 9 years ago
parent
commit
27d3ec8fb1

+ 19 - 0
message/migrations/0007_auto_20160907_1740.py

@@ -0,0 +1,19 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.db import models, migrations
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('message', '0006_systemmessageinfo_src'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AlterField(
15
+            model_name='systemmessageinfo',
16
+            name='src',
17
+            field=models.IntegerField(default=0, help_text='\u7cfb\u7edf\u6d88\u606f\u7c7b\u522b', db_index=True, verbose_name='src', choices=[(0, '\u62cd\u7231\u7528\u6237\u7aef'), (1, '\u62cd\u7231\u6444\u5f71\u5e08\u7aef')]),
18
+        ),
19
+    ]

+ 1 - 1
message/models.py

@@ -88,7 +88,7 @@ class SystemMessageInfo(CreateUpdateMixin):
88 88
     title = models.CharField(_(u'title'), max_length=255, help_text=u'系统消息标题')
89 89
     content = models.TextField(_(u'content'), blank=True, null=True, help_text=u'系统消息内容')
90 90
     url = models.CharField(_(u'url'), max_length=255, blank=True, null=True, help_text=u'系统消息链接')
91
-    src = models.IntegerField(_(u'src'), choices=SRC, default=PAIAI_USER, help_text=u'系统消息类别')
91
+    src = models.IntegerField(_(u'src'), choices=SRC, default=PAIAI_USER, help_text=u'系统消息类别', db_index=True)
92 92
 
93 93
     class Meta:
94 94
         verbose_name = _('systemmessageinfo')

+ 14 - 11
operation/admin.py

@@ -11,27 +11,30 @@ from utils.redis.rversion import delete_guest_entrance_control, set_guest_entran
11 11
 
12 12
 
13 13
 class LatestAppInfoAdmin(admin.ModelAdmin):
14
-    list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'latest_ios_version_code', 'latest_ios_version_name', 'latest_ios_url', 'status', 'created_at', 'updated_at')
14
+    list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'latest_ios_version_code', 'latest_ios_version_name', 'latest_ios_url', 'src', 'status', 'created_at', 'updated_at')
15
+    list_filter = ('src', 'status')
15 16
 
16 17
     def save_model(self, request, obj, form, change):
17 18
         obj.save()
18 19
 
19
-        # 更新安卓下载页面
20
-        write_to_disk(render_to_string('page/download.tmpl.html', {
21
-            'version': obj.latest_adr_version_name,
22
-        }), settings.DOWNLOAD_ADR_PAGE_PATH)
20
+        if obj.src == LatestAppInfo.PAIAI_USER:
21
+            # 更新安卓下载页面
22
+            write_to_disk(render_to_string('page/download.tmpl.html', {
23
+                'version': obj.latest_adr_version_name,
24
+            }), settings.DOWNLOAD_ADR_PAGE_PATH)
23 25
 
24
-        # 更新 iOS 下载页面
25
-        write_to_disk(render_to_string('page/download.tmpl.html', {
26
-            'version': obj.latest_ios_version_name,
27
-        }), settings.DOWNLOAD_IOS_PAGE_PATH)
26
+            # 更新 iOS 下载页面
27
+            write_to_disk(render_to_string('page/download.tmpl.html', {
28
+                'version': obj.latest_ios_version_name,
29
+            }), settings.DOWNLOAD_IOS_PAGE_PATH)
28 30
 
29 31
         # 设置最新 APP 信息
30
-        set_latest_app()
32
+        set_latest_app(obj.src)
31 33
 
32 34
 
33 35
 class SplashInfoAdmin(admin.ModelAdmin):
34
-    list_display = ('splash_image', 'spalash_image_airtime', 'spalash_image_deadline', 'status', 'created_at', 'updated_at')
36
+    list_display = ('splash_image', 'spalash_image_airtime', 'spalash_image_deadline', 'src', 'status', 'created_at', 'updated_at')
37
+    list_filter = ('src', 'status')
35 38
 
36 39
 
37 40
 class FeedbackInfoAdmin(admin.ModelAdmin):

+ 29 - 0
operation/migrations/0007_auto_20160907_1740.py

@@ -0,0 +1,29 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.db import models, migrations
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('operation', '0006_feedbackinfo_src'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='latestappinfo',
16
+            name='src',
17
+            field=models.IntegerField(default=0, help_text='\u6700\u65b0\u7248\u6765\u6e90', db_index=True, verbose_name='src', choices=[(0, '\u62cd\u7231\u7528\u6237\u7aef'), (1, '\u62cd\u7231\u6444\u5f71\u5e08\u7aef')]),
18
+        ),
19
+        migrations.AddField(
20
+            model_name='splashinfo',
21
+            name='src',
22
+            field=models.IntegerField(default=0, help_text='\u542f\u52a8\u9875\u9762\u6765\u6e90', db_index=True, verbose_name='src', choices=[(0, '\u62cd\u7231\u7528\u6237\u7aef'), (1, '\u62cd\u7231\u6444\u5f71\u5e08\u7aef')]),
23
+        ),
24
+        migrations.AlterField(
25
+            model_name='feedbackinfo',
26
+            name='src',
27
+            field=models.IntegerField(default=0, help_text='\u7528\u6237\u53cd\u9988\u6765\u6e90', db_index=True, verbose_name='src', choices=[(0, '\u62cd\u7231\u7528\u6237\u7aef'), (1, '\u62cd\u7231\u6444\u5f71\u5e08\u7aef')]),
28
+        ),
29
+    ]

+ 20 - 1
operation/models.py

@@ -23,6 +23,14 @@ def upload_path(instance, old_filename):
23 23
 
24 24
 
25 25
 class LatestAppInfo(CreateUpdateMixin):
26
+    PAIAI_USER = 0
27
+    PAIAI_LENSMAN = 1
28
+
29
+    SRC = (
30
+        (PAIAI_USER, u'拍爱用户端'),
31
+        (PAIAI_LENSMAN, u'拍爱摄影师端'),
32
+    )
33
+
26 34
     latest_adr_version_code = models.IntegerField(_(u'latest_adr_version_code'), default=0, help_text=u'最新安卓版本号')
27 35
     latest_adr_version_name = models.CharField(_(u'latest_adr_version_name'), max_length=255, blank=True, null=True, help_text=u'最新安卓版本名')
28 36
     latest_adr_app = models.FileField(_(u'latest_adr_app'), upload_to=upload_path, blank=True, null=True, help_text=u'最新版安卓 APP')
@@ -32,6 +40,8 @@ class LatestAppInfo(CreateUpdateMixin):
32 40
     latest_ios_version_name = models.CharField(_(u'latest_ios_version_name'), max_length=255, blank=True, null=True, help_text=u'最新 iOS 版本名')
33 41
     latest_ios_url = models.URLField(_(u'latest_ios_url'), max_length=255, blank=True, null=True, help_text=u'最新版 iOS 链接')
34 42
 
43
+    src = models.IntegerField(_(u'src'), choices=SRC, default=PAIAI_USER, help_text=u'最新版来源', db_index=True)
44
+
35 45
     class Meta:
36 46
         verbose_name = _('latestappinfo')
37 47
         verbose_name_plural = _('latestappinfo')
@@ -56,9 +66,18 @@ class LatestAppInfo(CreateUpdateMixin):
56 66
 
57 67
 
58 68
 class SplashInfo(CreateUpdateMixin):
69
+    PAIAI_USER = 0
70
+    PAIAI_LENSMAN = 1
71
+
72
+    SRC = (
73
+        (PAIAI_USER, u'拍爱用户端'),
74
+        (PAIAI_LENSMAN, u'拍爱摄影师端'),
75
+    )
76
+
59 77
     splash_image = models.ImageField(_(u'splash_image'), upload_to=upload_path, blank=True, null=True, help_text=u'启动页面图片')
60 78
     spalash_image_airtime = models.DateTimeField(_(u'spalash_image_airtime'), blank=True, null=True, help_text=u'启动页面图片开始日期')
61 79
     spalash_image_deadline = models.DateTimeField(_(u'spalash_image_deadline'), blank=True, null=True, help_text=u'启动页面图片截止日期')
80
+    src = models.IntegerField(_(u'src'), choices=SRC, default=PAIAI_USER, help_text=u'启动页面来源', db_index=True)
62 81
 
63 82
     class Meta:
64 83
         verbose_name = _('splashinfo')
@@ -91,7 +110,7 @@ class FeedbackInfo(CreateUpdateMixin):
91 110
 
92 111
     user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
93 112
     feedback = models.TextField(_(u'feedback'), blank=True, null=True, help_text=u'用户反馈')
94
-    src = models.IntegerField(_(u'src'), choices=SRC, default=PAIAI_USER, help_text=u'用户反馈来源')
113
+    src = models.IntegerField(_(u'src'), choices=SRC, default=PAIAI_USER, help_text=u'用户反馈来源', db_index=True)
95 114
 
96 115
     class Meta:
97 116
         verbose_name = _('feedbackinfo')

+ 6 - 2
operation/views.py

@@ -18,7 +18,9 @@ def upgrade_api(request):
18 18
     :param request:
19 19
     :return:
20 20
     """
21
-    latest_app = get_latest_app()
21
+    src = int(request.POST.get('src', 0))
22
+
23
+    latest_app = get_latest_app(src)
22 24
 
23 25
     if request.iOS:
24 26
         appinfo = {
@@ -45,7 +47,9 @@ def splash_api(request):
45 47
     :param request:
46 48
     :return:
47 49
     """
48
-    splashes = SplashInfo.objects.all()
50
+    src = int(request.POST.get('src', 0))
51
+
52
+    splashes = SplashInfo.objects.filter(src=src, status=True)
49 53
     splashes = [splash.data for splash in splashes]
50 54
 
51 55
     return response(200, 'Get Splash Success', u'获取最新版信息成功', {

+ 5 - 5
utils/redis/rapp.py

@@ -14,16 +14,16 @@ r = settings.REDIS_CACHE
14 14
 # 最新 APP 相关
15 15
 
16 16
 
17
-def set_latest_app():
17
+def set_latest_app(src=0):
18 18
     """ 设置最新 APP 信息 """
19 19
     try:
20
-        appinfo = LatestAppInfo.objects.all()[0].data
20
+        appinfo = LatestAppInfo.objects.filter(src=src)[0].data
21 21
     except IndexError:
22 22
         appinfo = {}
23
-    r.set(LATEST_APP_INFO, json.dumps(appinfo))
23
+    r.set(LATEST_APP_INFO % src, json.dumps(appinfo))
24 24
     return appinfo
25 25
 
26 26
 
27
-def get_latest_app():
27
+def get_latest_app(src=0):
28 28
     """ 获取最新 APP 信息 """
29
-    return json.loads(r.get(LATEST_APP_INFO) or '{}') or set_latest_app()
29
+    return json.loads(r.get(LATEST_APP_INFO % src) or '{}') or set_latest_app(src)

+ 1 - 1
utils/redis/rkeys.py

@@ -48,4 +48,4 @@ SYSTEM_MESSAGE_DELETED_INFO = 'system:message:deleted:info:%s'  # STRING,系
48 48
 GUEST_ENTRANCE_CONTROL_INFO = 'guest:entrance:control:info'  # STRING,游客入口控制信息
49 49
 
50 50
 # APP 相关
51
-LATEST_APP_INFO = 'latest:app:info'  # STRING,最新 APP 信息
51
+LATEST_APP_INFO = 'latest:app:info:%s'  # STRING,最新 APP 信息,src